//
//  ScanCodeViewController.m
//  XiXi
//
//  Created by HawkingWang on 16/9/29.
//  Copyright © 2016年 xi-xi.cc. All rights reserved.
//

#import "ScanCodeViewController.h"

#import "OnlineDetailTitleTableViewCell.h"//cell1
#import "DataTableViewCell.h"//cell2

#import "ScanningCodeViewController.h"//信息扫描


@interface ScanCodeViewController () <UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) UITableView *tableView;

@end

@implementation ScanCodeViewController
 static NSString *const DataTableViewCellID = @"DataTableViewCell";
 static NSString *const OnlineDetailTitleTableViewCellID = @"OnlineDetailTitleTableViewCell";

- (void)viewDidLoad {
    [super viewDidLoad];
    self.automaticallyAdjustsScrollViewInsets = NO;

    //设置导航栏
    [self setNav];
    
    //注册TableView
    [self registerTableView];
}

- (void)setNav{
    UIBarButtonItem *close = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"off"] style:UIBarButtonItemStylePlain target:self action:@selector(back)];
    self.navigationItem.leftBarButtonItem = close;
}
- (void)back{
    [self dismissViewControllerAnimated:YES completion:nil];
}


#pragma mark === 注册TableView ===
- (void)registerTableView{
    [self.tableView registerNib:[UINib nibWithNibName:@"OnlineDetailTitleTableViewCell" bundle:nil] forCellReuseIdentifier:OnlineDetailTitleTableViewCellID];
    [self.tableView registerNib:[UINib nibWithNibName:@"DataTableViewCell" bundle:nil] forCellReuseIdentifier:DataTableViewCellID];
}

#pragma mark === TableViewDelegate ===
//section数
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 2;
}
//行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section == 0) {
        return 1;
    }
    return 8;
}
//行高
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        return 50;
    }
    return 145;
}
//Reusable
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        OnlineDetailTitleTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:OnlineDetailTitleTableViewCellID];
        cell.title.text = @"- 选择开始检票的场次 -";
        cell.detail.text = @"数据准备完成的场次才能进行检票";
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }
    DataTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:DataTableViewCellID];
//    [cell loadData:<#(DataModel *)#>];
    cell.title.text = @"阿加莎推理巨作——爱乐汇·拉得斯基进行曲——世界";
    cell.time.text = @"2016.01.30 19:30 ~ 21:30";
    cell.theatre.text = @"西溪天堂艺术中心剧院名称";
    cell.hall.text = @"Interting演出厅名称";
    [cell.dataBtn setTitle:@"开始检票" forState:UIControlStateNormal];
    
    cell.dataBtnClick = ^(){
        DLog(@"开始检票");
        ScanningCodeViewController *scanning = [[ScanningCodeViewController alloc] init];
        [self.navigationController pushViewController:scanning animated:YES];
    };
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}

- (UITableView *)tableView{
    if (!_tableView) {
        _tableView= [[UITableView alloc]initWithFrame:CGRectMake(0,4, SCREEN_WIDTH, SCREEN_HEIGHT - 68)style:UITableViewStylePlain];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.showsVerticalScrollIndicator = NO;//去掉滑动竖条
        _tableView.backgroundColor = RGBCOLOR(236, 234, 228);
        [self.view addSubview:_tableView];
    }
    return _tableView;
}

@end
